/**
 * Created by Administrator on 2017/9/4.
 */

    var setting = new Object();

    setting.init = function () {
        //var domain = setting.parseDomain();
        var domain = $("#domain").val();
        if(!domain) {
            // 解析不到个性化域名,直接return
            return;
        }

        var params = {
            'domain': domain
        };
        $.ajax({
            url: appPath + "/domain/info",
            data: params,
            type: "post",
            dataType:"json",
            success: function(data) {
                var code = data.code;
                if("10000" == code){
                    var companySetting = data.result;
                    if(!companySetting) {
                        return;
                    }
                    var companyId = companySetting.companyId;
                    if(!companyId) {
                        return;
                    }
                    // 域名登录页companyId赋值
                    $("#companyId").val(companyId);
                    // 本地存储个性化信息
                    localStorage.setItem(companyId, JSON.stringify(companySetting));
                    // 设置个性化登录页面的平台logo-cp_logo、平台名称-cp_plat_name、平台大图-cp_login_img
                    var cpPlatName = companySetting.cpPlatName;
                    if(cpPlatName) {
                        $("#cpPlatName").html(cpPlatName);
                    }
                    var cpLogo = companySetting.cpLogo;
                    if(cpLogo) {
                        $("#cpLogo").attr("src", cpLogo);
                        $("#cpLogo").attr("alt", cpLogo);
                    }
                    var cpLoginImg = companySetting.cpLoginImg;
                    if(cpLoginImg) {
                        $("#cpLoginImg").css("background-image", "url("+ cpLoginImg + ")");
                        $("#login_bg").css("display","none");
                        $("#cpLoginImg").css("background-size", "cover");
                    }
                }
            }
        });
    };

    setting.parseDomain = function () {
        var url = window.location.href;
        var from = url.lastIndexOf("/");
        var to = url.lastIndexOf(".htm");
        if(-1!=from && -1!=to)
            return url.substr(from + 1, (to - from -1));
        return "";
    };
